package com.liu.nb.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.liu.nb.dto.GetPoleByCircuitryDto;
import com.liu.nb.entity.Pole;
import com.liu.nb.util.Result;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 塔杆表 塔杆管理 前端控制器
 * </p>
 *
 * @author liuziyi
 * @since 2021-08-31
 */
@RestController
@RequestMapping("/nb/pole")
public class PoleController extends BaseController {
    /** 查询所有线路 */
    @RequestMapping("/getAllCir")
    public Result getAllCir() {
        List<GetPoleByCircuitryDto> poleCircuityDto = iCircuitryService.getPoleCircuityDto();
        return Result.success(poleCircuityDto);
    }

     /*查询塔杆*/
    @PostMapping("/list/{current}/{size}") /*分页条件*/                          /*查询参数 根据线路查 circuity  根据状态查 state*/
    public Result getPoleList(@PathVariable int current, @PathVariable int size, @RequestBody HashMap<String, Object> map) {
        Page<Pole> page = poleService.getPoleInfo(map, current, size);
        return Result.success(page);
    }
    /*
    * 修改塔杆
    * */
    @PostMapping("/update/pole")
    public Result updatePole(@RequestBody Pole pole){
        boolean b = poleService.updateById(pole);
        return Result.success(b);
    }
    /*
    * 添加塔杆
    * */
    @PreAuthorize("hasAnyRole('root','xianluadmin')")
    @PostMapping("/add/pole")
    public Result addPole(@RequestBody Pole pole){
        boolean save = poleService.save(pole);
        return Result.success(save);
    };
    /*
    * 删除塔杆
    * */
    @PreAuthorize("hasAnyRole('root','xianluadmin')")
    @RequestMapping("/del/pole/{id}")
    public Result delPole(@PathVariable String id){
        boolean b = poleService.remove(new QueryWrapper<Pole>().eq("id",id));
        return Result.success(b);
    }
}
